package com.t235.gc.order.controller;

import com.t235.gc.AjaxResult;
import com.t235.gc.entity.GarbageRecyclingOrder;
import com.t235.gc.order.service.GarbageRecyclingOrderService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api
@RestController
public class GarbageRecyclingOrderController {
    @Autowired
    private GarbageRecyclingOrderService garbageRecyclingOrderService;

//    @PostMapping("/selectAll")
//    public AjaxResult selectAll(){
//        List<GarbageRecyclingOrder> list=garbageRecyclingOrderService.selectAll();
//        return AjaxResult.success(list);
//    }

//    @GetMapping("/select")
//    public AjaxResult select(GarbageRecyclingOrder garbageRecyclingOrder, String nickname, String userphone,
//                             String begindate, String finishdate, Integer recyclingtype,
//                             @RequestParam(value = "page",defaultValue = "0")Integer pageNo,
//                             @RequestParam(value = "limit",defaultValue = "2")Integer pageSize) throws ParseException {
//        PageHelper.startPage(pageNo,pageSize);
//        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
//        List<GarbageRecyclingOrder> list=new ArrayList<>();
//        if(begindate!=null&&finishdate!=null&&begindate!=""&&finishdate!="") {
//            list=garbageRecyclingOrderService.select(garbageRecyclingOrder,nickname,userphone,dateFormat.parse(begindate),dateFormat.parse(finishdate),recyclingtype);
//        }else{
//            list=garbageRecyclingOrderService.select(garbageRecyclingOrder,
//                    nickname,userphone,null,null,recyclingtype);
//        }
//        PageInfo<GarbageRecyclingOrder> pageInfo = new PageInfo<>(list);
//        return AjaxResult.success(pageInfo);
//    }

    //创建用户投递垃圾总订单并返回订单号
    @RequestMapping("/insertGarbageRecyclingOrder")
    public AjaxResult insertGarbageRecyclingOrder(GarbageRecyclingOrder garbageRecyclingOrder){
        //产生一个随机的订单号
        garbageRecyclingOrder.setOrderid(System.currentTimeMillis());
        garbageRecyclingOrderService.insertGarbageRecyclingOrder(garbageRecyclingOrder);
        return AjaxResult.success(garbageRecyclingOrder.getOrderid());
    }
    //提现，查询当前用户得总积分
    //通过积分在前端算出可兑换的现金
    @GetMapping("/selectAccPointsByUserId")
    public AjaxResult selectAccPointsByUserId(Long userid){
        GarbageRecyclingOrder garbageRecyclingOrder=garbageRecyclingOrderService.selectAccPointsByUserId(userid);
        return AjaxResult.success(garbageRecyclingOrder.getAccpoints());
    }



}
